using MicroMsg.Manager;
using MicroMsg.Resource.@string;
using MicroMsg.Storage;
using MicroMsg.UI.UserContrl;
using System;
namespace MicroMsg.UI.Model
{
	public class MsgInfoObject
	{
		public static int RECEIVER = 0;
		public static int SENDER = 1;
		private static string getDisplayContentForMBOrQQMsg(int isSender, string username, string content, string suffix)
		{
			if (ContactHelper.isMicroBlogPrivateMsgHelper(username))
			{
				return "启用";
			}
			if (ContactHelper.isQQOffLineMessageHelper(username))
			{
				return "启用";
			}
			string text = "";
			if (!ContactHelper.isMicroBlogPrivateMsgHelper(username) && !ContactHelper.isQQOffLineMessageHelper(username))
			{
				if (ContactHelper.isTContact(username) || ContactHelper.isQContact(username))
				{
					text = ContactHelper.getDisplayName(username, null);
					if (isSender == MsgInfoObject.SENDER)
					{
						return string.Format("我回复{0}:", "") + ((suffix == null) ? content : suffix);
					}
					if (suffix != null)
					{
						return suffix;
					}
					return content;
				}
			}
			else
			{
				if (content != null)
				{
					int num = content.IndexOf(ConstantValue.TMESSAGE_OR_QMESSAGE_CONTENT_SEPERATOR);
					if (num >= 0 && num < content.get_Length())
					{
						string username2 = content.Substring(0, num);
						if (ContactHelper.isTContact(username2) || ContactHelper.isQContact(username2))
						{
							text = ContactHelper.getDisplayName(username2, null);
							content = content.Substring(num + 1);
						}
					}
				}
			}
			if (text != null && text.get_Length() > 0)
			{
				return string.Format((isSender == MsgInfoObject.SENDER) ? "我回复{0}:" : "{0}:", text) + ((suffix == null) ? content : suffix);
			}
			if (suffix != null)
			{
				return suffix;
			}
			return content;
		}
		public static string parseMsgContentToShow(Conversation conv, ref string preUserNickName)
		{
			preUserNickName = null;
			if (conv == null)
			{
				return "";
			}
			ChatMsg chatMsg = new ChatMsg();
			if (!(conv.strUsrName == "qmessage") && !(conv.strUsrName == "floatbottle"))
			{
				chatMsg.strTalker = conv.strUsrName;
			}
			else
			{
				chatMsg.strTalker = conv.strNickName;
			}
			chatMsg.strMsg = conv.strContent;
			chatMsg.nIsSender = conv.nIsSend;
			try
			{
				chatMsg.nMsgType = int.Parse(conv.strMsgType);
			}
			catch (Exception)
			{
				chatMsg.nMsgType = 1;
			}
			return MsgInfoObject.parseMsgContentToShow(chatMsg, ref preUserNickName);
		}
		public static string parseMsgContentToShow(ChatMsg chatMsg_0, ref string preUserNickName)
		{
			preUserNickName = null;
			if (chatMsg_0 == null)
			{
				return "";
			}
			if (string.IsNullOrEmpty(chatMsg_0.strTalker))
			{
				return "";
			}
			if (chatMsg_0.strMsg == null)
			{
				chatMsg_0.strMsg = "";
			}
			string text = "";
			string text2 = "";
			int nMsgType = chatMsg_0.nMsgType;
			if (nMsgType <= 13)
			{
				switch (nMsgType)
				{
				case 1:
					text = chatMsg_0.strMsg;
					if (ContactHelper.isChatRoom(chatMsg_0.strTalker))
					{
						if (chatMsg_0.nIsSender == 1)
						{
							goto IL_534;
						}
						string text3 = "";
						if (ChatMsgMgr.getMsgUser(chatMsg_0, ref text2, ref text3))
						{
							text = text3;
							goto IL_534;
						}
						goto IL_534;
					}
					else
					{
						if (ContactHelper.isBottleContact(chatMsg_0.strTalker))
						{
							if (chatMsg_0.nIsSender == 1)
							{
								text = strings.Plugin_QQOffline_IReply + ": " + text;
								goto IL_534;
							}
							if (string.IsNullOrEmpty(text))
							{
								text = "";
								goto IL_534;
							}
							text = ContactHelper.getDisplayName(chatMsg_0.strTalker, null) + ": " + text;
							goto IL_534;
						}
						else
						{
							if (!ContactHelper.isNewsContact(chatMsg_0.strTalker))
							{
								goto IL_534;
							}
							TXNews tXNews = NewsMgr.parseNewsXml(chatMsg_0.strMsg);
							if (tXNews == null)
							{
								preUserNickName = text;
								goto IL_534;
							}
							if (tXNews != null)
							{
								preUserNickName = tXNews.strDescipt;
								NewsMgr.getNewsImg(tXNews.strCoverImgUrl);
								goto IL_534;
							}
							goto IL_534;
						}
					}
					break;
				case 2:
					break;
				case 3:
					goto IL_49C;
				default:
					switch (nMsgType)
					{
					case 11:
						text = "暂时不支持的消息格式";
						goto IL_534;
					case 13:
						text = "暂时不支持的消息格式";
						goto IL_534;
					}
					break;
				}
			}
			else
			{
				if (nMsgType == 23)
				{
					goto IL_49C;
				}
				switch (nMsgType)
				{
				case 33:
					goto IL_49C;
				case 34:
					text = strings.ChatVoiceContent;
					if (ContactHelper.isChatRoom(chatMsg_0.strTalker))
					{
						if (chatMsg_0.nIsSender == 1)
						{
							goto IL_534;
						}
						string text4 = "";
						if (ChatMsgMgr.getMsgUser(chatMsg_0, ref text2, ref text4))
						{
							goto IL_534;
						}
						goto IL_534;
					}
					else
					{
						if (ContactHelper.isQContact(chatMsg_0.strTalker))
						{
							string displayName = ContactHelper.getDisplayName(chatMsg_0.strTalker, null);
							if (chatMsg_0.IsSender())
							{
								preUserNickName = strings.Plugin_QQOffline_IReply + displayName + ": ";
								goto IL_534;
							}
							preUserNickName = displayName + ": ";
							goto IL_534;
						}
						else
						{
							if (!ContactHelper.isBottleContact(chatMsg_0.strTalker))
							{
								goto IL_534;
							}
							string displayName2 = ContactHelper.getDisplayName(chatMsg_0.strTalker, null);
							if (chatMsg_0.IsSender())
							{
								preUserNickName = strings.Plugin_QQOffline_IReply + ": ";
								goto IL_534;
							}
							preUserNickName = displayName2 + ": ";
							goto IL_534;
						}
					}
					break;
				case 35:
				case 38:
				case 41:
				case 44:
				case 45:
				case 46:
					break;
				case 36:
					if (chatMsg_0.IsSender())
					{
						text = strings.Plugin_QQOffline_IReply + ContactHelper.getDisplayName(chatMsg_0.strTalker, null) + ": " + chatMsg_0.strMsg;
						goto IL_534;
					}
					if (string.IsNullOrEmpty(chatMsg_0.strMsg))
					{
						return "";
					}
					if (!ChatMsgMgr.getQQOfflineMsg(chatMsg_0.strMsg, ref text2, ref text))
					{
						string displayName3 = ContactHelper.getDisplayName(chatMsg_0.strTalker, null);
						text = displayName3 + ": [" + strings.MessageContent_SendMessage_NotSupport + "]";
						goto IL_534;
					}
					if (string.IsNullOrEmpty(text))
					{
						text = "";
						goto IL_534;
					}
					if (string.IsNullOrEmpty(text2))
					{
						text2 = ContactHelper.getDisplayName(chatMsg_0.strTalker, null);
					}
					text = text2 + ": " + text;
					goto IL_534;
				case 37:
					text = chatMsg_0.strMsg;
					goto IL_534;
				case 39:
					text = strings.Plugin_QQOffline_IReply + ContactHelper.getDisplayName(chatMsg_0.strTalker, null) + ": " + strings.ChatImgContent;
					goto IL_534;
				case 40:
				{
					IFmessageInfo fmessageInfo = FMessageHelper.ParseFriendFMessageXML(chatMsg_0.strMsg);
					if (fmessageInfo == null)
					{
						text = "";
						goto IL_534;
					}
					text = fmessageInfo.ConversationInfo;
					goto IL_534;
				}
				case 42:
					text = chatMsg_0.strMsg;
					goto IL_534;
				case 43:
				{
					text = strings.ChatVideoContent;
					if (!ContactHelper.isChatRoom(chatMsg_0.strTalker) || chatMsg_0.nIsSender == 1)
					{
						goto IL_534;
					}
					string text5 = "";
					if (ChatMsgMgr.getMsgUser(chatMsg_0, ref text2, ref text5))
					{
						goto IL_534;
					}
					goto IL_534;
				}
				case 47:
					if (ContactHelper.isChatRoom(chatMsg_0.strTalker) && chatMsg_0.nIsSender != 1)
					{
						string text6 = "";
						ChatMsgMgr.getMsgUser(chatMsg_0, ref text2, ref text6);
					}
					text = strings.ChatCustomSmileyContent;
					goto IL_534;
				case 48:
					if (chatMsg_0.nIsSender == 1)
					{
						return strings.Chat_My_Location;
					}
					if (ContactHelper.isChatRoom(chatMsg_0.strTalker))
					{
						string text7 = "";
						if (ChatMsgMgr.getMsgUser(chatMsg_0, ref text2, ref text7))
						{
							text7 = text;
						}
					}
					else
					{
						text2 = chatMsg_0.strTalker;
					}
					return string.Format(strings.Chat_Others_Location, ContactHelper.getDisplayName(text2, null));
				default:
					if (nMsgType == 10000)
					{
						text = chatMsg_0.strMsg;
						goto IL_534;
					}
					break;
				}
			}
			text = chatMsg_0.strMsg;
			goto IL_534;
			IL_49C:
			text = strings.ChatImgContent;
			if (ContactHelper.isChatRoom(chatMsg_0.strTalker))
			{
				if (chatMsg_0.nIsSender != 1)
				{
					string text8 = "";
					if (ChatMsgMgr.getMsgUser(chatMsg_0, ref text2, ref text8))
					{
					}
				}
			}
			else
			{
				if (ContactHelper.isQContact(chatMsg_0.strTalker))
				{
					text = ContactHelper.getDisplayName(chatMsg_0.strTalker, null) + ": " + text;
				}
				else
				{
					if (ContactHelper.isBottleContact(chatMsg_0.strTalker))
					{
						if (chatMsg_0.IsSender())
						{
							text = strings.Plugin_QQOffline_IReply + ": " + text;
						}
						else
						{
							text = ContactHelper.getDisplayName(chatMsg_0.strTalker, null) + ": " + text;
						}
					}
				}
			}
			IL_534:
			if (text == null)
			{
				text = "";
			}
			if (chatMsg_0.nMsgType == 42)
			{
				return text;
			}
			if (ContactHelper.isChatRoom(chatMsg_0.strTalker) && chatMsg_0.nIsSender != 1 && !string.IsNullOrEmpty(text2) && text2 != chatMsg_0.strTalker)
			{
				string displayName4 = ContactHelper.getDisplayName(text2, null);
				preUserNickName = displayName4 + ": ";
			}
			if (text == null)
			{
				text = "";
			}
			return text;
		}
		public static string getGroupChatMsgToShow(string msgContent)
		{
			int num = MsgInfoObject.parseGroupChatMsg(msgContent);
			if (num == -1)
			{
				return msgContent;
			}
			string text = msgContent.Substring(0, num).Trim();
			string displayName = ContactHelper.getDisplayName(text, null);
			if (displayName != null && displayName.get_Length() > 0)
			{
				msgContent = msgContent.Replace(text, displayName);
			}
			return msgContent;
		}
		public static int parseGroupChatMsg(string text)
		{
			if (text == null)
			{
				return -1;
			}
			int num = text.IndexOf(':', -1 + 1);
			if (num != -1)
			{
				return num;
			}
			return -1;
		}
		public static int getMsgType(string msgType)
		{
			int result = 1;
			if (msgType != null && msgType.get_Length() > 0)
			{
				try
				{
					result = int.Parse(msgType);
				}
				catch (Exception)
				{
					result = 1;
				}
			}
			return result;
		}
	}
}
